/**
 * Starts the program.
 */

#include <stdio.h>
#include <stdlib.h>
#include "cpu.h"

#define MAX_NUMBER_OF_PROCESSES 96

#define DEFAULT_SCHEDULER_TYPE 0

int total = 0;
void validate(int);


int main() {
	CPU cpu;
	int scheduler_type;
	int ui = 1;
	int calc = 1;
	int producer = 1;
	int consumer = 1;

	printf("Please enter the number of processes you would like to (maximum 100) \n");
	printf("You must also choose at least one of each process : \n");
	printf("How many UI processes would you like to create? ");
	fflush(stdout);
	scanf("%d", &ui);
	validate(ui);
	if(total < 100) {
		printf("\nHow many Calculation processes would you like? ");
		fflush(stdout);
		scanf("%d", &calc);
		validate(calc);

		if(total < 100) {
			printf("\nHow many Producer processes would you like? ");
			fflush(stdout);
			scanf("%d", &producer);
			validate(producer);

			if(total < 100) {
				printf("\nHow many Consumer processes would you like? ");
				fflush(stdout);
				scanf("%d", &consumer);
				validate(consumer);
			}
		}
	}
	printf("What type of scheduling system would you like to use? (enter 0 for round robin, 1 for priority, and 2 for lottery)");
	fflush(stdout);
	scanf("%d", &scheduler_type);
	cpu = newCPU(ui, calc, producer, consumer, scheduler_type);
	runCPU(cpu);
	return 0;
}

void validate(int nbr) {
	if (total + nbr < MAX_NUMBER_OF_PROCESSES) {
		total += nbr;
	} else {
		fflush(stdout);
		printf("Too many processes have been entered. \n");
		printf("Please start over.");
		total += nbr;
	}
	return;
}
